<%--
Created by IntelliJ IDEA.
User: DELL
Date: 2021/4/1
Time: 15:29
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>新增</title>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>

  </head>
  
  <body>
    <div class="x-body">
        <form id="uploadForm" name = form2 class ="layui-form">
            <div class="layui-form-item">
                <label for="userId" class="layui-form-label">
                    <span class="x-red">*</span>商家ID
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userId" name="userId" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>商家ID
                </div>
            </div>
            <div class="layui-form-item">
                <label for="g_name" class="layui-form-label">
                    <span class="x-red">*</span>商品名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="g_name" name="g_name" required="" lay-verify="phone"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>商品名称
                </div>
            </div>
            <div class="layui-form-item">
                <label for="g_prices" class="layui-form-label">
                    <span class="x-red">*</span>商品单价
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="g_prices" name="g_prices" required="" lay-verify="phone"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>商品单价
                </div>
            </div>

            <div class="layui-form-item">
                <label for="g_number" class="layui-form-label">
                    <span class="x-red">*</span>商品数量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="g_number" name="g_number" required="" lay-verify="email"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>商品数量
                </div>
            </div>

            <div class="layui-form-item">
                <label for="selectShopTpye" class="layui-form-label">
                    <span class="x-red">*</span>商品类型
                </label>
                <div class="layui-input-inline">
                    <select id="selectShopTpye" name="selectShopTpye" class="selected-inline" >
                        <option value="4" class="selected-inline selected">待选择</option>
                        <option value="1"  >学习用品</option>
                        <option value="2" >生活用品</option>
                        <option value="3" >体育用品</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="uploadForm" class="layui-form-label">
                    <span class="x-red">*</span>商品图片
                </label>
                <%--              action="${pageContext.request.contextPath}/goods/selectGoodsPhotos"  enctype="multipart/form-data" method="post"--%>
                <div class="layui-input-inline">

                    <%-- multiple：允许你选择多个文件--%>
                    <input type="file" name="file" multiple="multiple"/>
                    <%--                <input type="button" value="上传" onclick="function1()"/>--%>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label">
                        </label>
                        <button  class="layui-btn" onclick="function1()">
                            提交审核
                        </button>
                    </div>
                </div>
                <br>
                <span style="color: red">${info}</span>
            </div>
        </form>
    </div>
    <script>
        function function1() {
            var form = new FormData(document.getElementById('uploadForm'));
            var userId = form.get("userId");
            alert(form.get("g_prices"))
            var g_prices = form.get("g_prices");
            var g_name = form.get("g_name");
            var g_number = form.get("g_number");
            var selectShopTpye = form.get("selectShopTpye");
            $.ajax({
                url: "${pageContext.request.contextPath}/goods/selectGoodsPhotos",
                type: "post",
                data: form,
                dataType:"json",
                processData: false,
                contentType: false,
                success: function (data) {
                    console.log(data.info);
                }
            });
        }
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
          });
          
          
        });
    </script>

  </body>

</html>